using System;
using System.Reflection;
using Microsoft.XLANGs.BaseTypes;
using System.Resources;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using Microsoft.BizTalk.XLANGs.BTXEngine;

namespace BTSProjectWizard
{
	public  class BTSWizardPage : System.Windows.Forms.UserControl
	{
		protected  Wizard wizard = Wizard.TheWizard;
        protected OpenFileDialog openFileDialog1;
        public BTSWizardPage()
        {
            this.InitializeComponent();
        }
		private void InitializeComponent()
		{
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.SuspendLayout();
            // 
            // openFileDialog1
            // 
            this.openFileDialog1.FileName = "openFileDialog1";
            // 
            // BTSWizardPage
            // 
            this.Name = "BTSWizardPage";
            this.Size = new System.Drawing.Size(759, 416);
            this.ResumeLayout(false);

		}
        protected ResourceManager _rm = new ResourceManager("BTSProjectWizard.Resources.Strings", Assembly.GetExecutingAssembly());
	
        protected Assembly LoadBizTalkAssembly(string asmname)
        {
            Assembly asm = Assembly.LoadFrom(asmname);
            object[] oa = asm.GetCustomAttributes(typeof(BizTalkAssemblyAttribute), true);
            if (oa == null || oa.Length == 0)
            {
                MessageBox.Show(_rm.GetString("NotABizTalkAssembly", Thread.CurrentThread.CurrentCulture));
                return null;
            }
            return asm;
        }
        protected List<Type> GetBizTalkType(Assembly asm, Type baseType)
        {
            List<Type> ret = new List<Type>();
            Type[] types = asm.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
               
                if (types[i].IsSubclassOf(baseType) )
                    ret.Add(types[i]);
            }
            return ret;
        }
        protected List<Type> GetPipelines(string asmname)
        {
            Assembly asm = LoadBizTalkAssembly(asmname);
            return GetPipelines(asm);
        }
        protected List<Type> GetPipelines(Assembly asm)
        {
            return GetBizTalkType(asm, typeof(PipelineBase));
        }
        protected List<Type> GetOrchs(string asmname)
        {
            Assembly asm = LoadBizTalkAssembly(asmname);
            return GetOrchs(asm);
        }
        protected List<Type> GetOrchs(Assembly asm)
        {
            return GetBizTalkType(asm,typeof(Microsoft.BizTalk.XLANGs.BTXEngine.BTXService));
        }
        protected List<Type> GetMaps(string asmname)
        {
            Assembly asm = LoadBizTalkAssembly(asmname);
            return GetMaps(asmname);
        }
        protected List<Type> GetMaps(Assembly asm)
        {
            return GetBizTalkType(asm, typeof(TransformBase));
        }
        protected List<Type> GetPortTypes(string asmname)
        {
            Assembly asm = LoadBizTalkAssembly(asmname);
            return GetPortTypes(asm);
        }
        protected List<Type> GetPortTypes(Assembly asm)
        {
            return GetBizTalkType(asm, typeof(BTXPortBase));
        }
        string _Data;
		public string Data
		{
			get{return _Data;}
			set{_Data=value;}
		}
		string _Title ="BizTalk Pattern Wizard";
		public virtual string Title
		{
			get{return _Title;}
			set{_Title = value;}
		}
		public virtual bool ProcessSymbols()
		{
			return true;
		}

	}
}
